package com.dayang.redbook.auth.controller;

import com.dayang.framework.biz.operationlog.aspect.ApiOperationLog;
import com.dayang.framework.common.domain.response.Response;
import com.dayang.redbook.auth.model.user.vo.UpdatePasswordReqVO;
import com.dayang.redbook.auth.model.user.vo.UserLoginReqVO;
import com.dayang.redbook.auth.service.AuthService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: dayang
 * @since: 2024/5/31
 * @description:
 */
@RestController
@Slf4j
@Tag(name = "用户认证",description = "用户登录注册退出等")
@ApiSupport(author = "dayang")
public class AuthController {
    @Resource
    private AuthService authService;

    @Operation(summary = "用户登录/注册")
    @PostMapping("/login")
    @ApiOperationLog("用户登录/注册")
    public Response<String> loginAndRegister(@Validated @RequestBody UserLoginReqVO userLoginReqVO) {
        return authService.loginAndRegister(userLoginReqVO);
    }


    @Operation(summary = "用户退出")
    @PostMapping("/logout")
    @ApiOperationLog("账号登出")
    public Response<?> logout(){
        return authService.logout();
    }


    @Operation(summary = "用户修改密码")
    @PostMapping("/password/update")
    @ApiOperationLog("修改密码")
    public Response<?> updatePassword(@Validated @RequestBody UpdatePasswordReqVO updatePasswordReqVO) {
        return authService.updatePassword(updatePasswordReqVO);
    }
}
